#include "aerial\Core\Acc.h"

#include "aerial\Object\Object.h"

using namespace air;

Acc::Acc(): head(NULL), tail(NULL) {}

Acc::~Acc() {  clear(); }

void Acc::clear()
{
	IObject *p = head, *q;
	while (p != NULL)
	{
		q = p->next;
		delete p;
		p = q;
	}
}

bool Acc::Update(float dt)
{
	for (IObject *p = head; p; p = p->next) p->update(dt);
	return false;
}

void Acc::Render()
{
	for (IObject *p = head; p; p = p->next) p->render();
}

void Acc::addObject(IObject* iObj)
{
	if (!head)
	{
		head = iObj;
		tail = iObj; 
	}
	else {
		tail->next = iObj;
		iObj->prev = tail;
	}
	iObj->acc = this;
}

void Acc::removeObject(IObject* iObj)
{
	if (iObj->next) iObj->next->prev = iObj->prev;
	else tail = iObj->prev;
	if (iObj->prev) iObj->prev->next = iObj->next;
	else head = iObj->next;
	delete iObj;
}

